
** CODE for replication of "Interpersonal Resources and Insider/Outsider Dynamics in Party Office "
** Authors: Javier Martínez-Cantó and Tània Verge
** Journal: Comparative Political Studies (CPS)

** Before running this code, please see the "readme_replication" file for general instructions. 
** All procedures and analysis were executed using STATA 14.1

****************************************************
*** Analysis 1: Uneven distribution of resources ***
****************************************************

*** Importing the dataset
clear 

use "data_necs.dta" // This dataset contains yearly observations for each NEC member

*** Installing required packages (if necesary)
*ssc install estout, replace
*ssc install blindschemes, replace
*ssc install coefplot, replace
*net install grc1leg, from(http://www.stata.com/users/vwiggins) replace

 set scheme plotplain

*** Keep only the observations capturing NEC members at their first year of tenure.
sort id_name year
stset nec_order_year, id(id_name_period) failure(nec_failure==1) 
keep if _t==1


**************************
*** Main text: Table 1 ***
**************************

*** Global capturing individual and interpersonal factors
** Individual factors
global individual 				age university_degree isei seniority national_politics_exp 
** Interpersonal factors
global interpersonal 			years_as_party_member youth_org leader_coincidence 

*** Calculation
** Mean, all
eststo total: quietly estpost summarize ///
    $individual $interpersonal  ///
	if _t==1
** Mean, men
eststo male: quietly estpost summarize ///
    $individual $interpersonal  ///
	if _t==1 & gender==0 
** Mean, women
eststo female: quietly estpost summarize ///
	$individual $interpersonal  ///
	if _t==1 & gender==1 
* T-test, difference men-women
eststo diff: quietly estpost ttest ///
	$individual $interpersonal  ///
	if _t==1 , by(gender) unequal

* Childless data in the sub-sample (only for PP and PSOE NEC members)
eststo total2: quietly estpost summarize childless  ///
	if _t==1 & party<3402
eststo male2: quietly estpost summarize childless  ///
	if _t==1 & gender==0 & party<3402
eststo female2: quietly estpost summarize childless  ///
	if _t==1 & gender==1 & party<3402
eststo diff2: quietly estpost ttest childless  ///
	if _t==1  & party<3402, by(gender) unequal
	
*** Export tables

esttab total male female diff, ///
cells("mean(pattern(1 1 1 0) fmt(2)) b(star pattern(0 0 0 1) fmt(2))  ") ///
label mtitle("Male" "Female" "Diff." "Male" "Female" "Diff.") compress

esttab total male female diff using "group_comparison.rtf", ///
cells("mean(pattern(1 1 1 0) fmt(2)) b(star pattern(0 0 0 1) fmt(2))  ") ///
label mtitle("Male" "Female" "Diff." "Male" "Female" "Diff.") compress replace

esttab total2 male2 female2 diff2, ///
cells("mean(pattern(1 1 1 0) fmt(2)) b(star pattern(0 0 0 1) fmt(2))  ") ///
label mtitle("Male" "Female" "Diff." "Male" "Female" "Diff.") compress

esttab total2 male2 female2 diff2 using "group_comparison_childless.rtf", ///
cells("mean(pattern(1 1 1 0) fmt(2)) b(star pattern(0 0 0 1) fmt(2))  ") ///
label mtitle("Male" "Female" "Diff." "Male" "Female" "Diff.") compress replace


*************************************************************************************************************
*** Appendix C: he distribution of political and interpersonalresources between men and women NEC members ***
*************************************************************************************************************

* The purpouse of these rebustness checks is to show that the gender-associated differences that we find in the first analysis is not contingent on year and party affiliation. 
replace childless = . if party>3401 // We run only the childless variable only on PP and PSOE NEC members
** Individual factors
global individual 				age university_degree isei seniority national_politics_exp childless
** Interpersonal factors
global interpersonal 			years_as_party_member youth_org leader_coincidence 

* Appendix C: Tables 2 to 7
*** Individual factors
foreach i of global individual {
label variable gender "Women"

quietly: regress `i' gender
eststo `i'_1
quietly: regress `i' gender year
eststo `i'_2
quietly: regress `i' gender i.party year
eststo `i'_3

esttab `i'_1 `i'_2 `i'_3  using "differences_access_`i'.tex", replace ///
compress se  noomitted  interaction(" X ") dropped("Ref.") nogaps star(* .05 ** .01 *** .001) ///	
mtitle("Model 1" "Model 2" "Model 3") label nonumbers booktabs longtable r2 scalars("ll Log lik.") alignment(D{.}{.}{-1}) title("`: var label `i''") 

label variable gender " "
}
*

* Appendix C: Tables 8 to 10 			   
*** Interpersonal factors
foreach i of global interpersonal {

label variable gender "Women"

quietly: regress `i' gender
eststo `i'_1
quietly: regress `i' gender year
eststo `i'_2
quietly: regress `i' gender i.party year
eststo `i'_3

esttab `i'_1 `i'_2 `i'_3 using "differences_access_`i'.tex", replace ///
compress se  noomitted  interaction(" X ") dropped("Ref.") nogaps star(* .05 ** .01 *** .001) ///	
mtitle("Model 1" "Model 2" "Model 3") label nonumbers booktabs longtable r2 scalars("ll Log lik.")  alignment(D{.}{.}{-1}) title("`: var label `i''") 

label variable gender " "
}
*

* Appendix C: Figure 4

coefplot (age_1, label("Women")) (age_2, label("Women + Year")) (age_3, label("Women + Year + Party FE")) , drop(_cons) xline(0) keep(gender) name(plot_age, replace) title("Age") legend(position(6) rows(1)) xlabel(0(1)-5)
coefplot (university_degree_1, label("Women")) (university_degree_2, label("Women + Year")) (university_degree_3, label("Women + Year + Party FE")) , drop(_cons) xline(0) keep(gender) name(plot_university_degree, replace) title("University degree") legend(position(6) rows(1)) 
coefplot (isei_1, label("Women")) (isei_2, label("Women + Year")) (isei_3, label("Women + Year + Party FE")) , drop(_cons) xline(0) keep(gender) name(plot_isei, replace) title("Occupational status") legend(position(6) rows(1)) 
coefplot (seniority_1, label("Women")) (seniority_2, label("Women + Year")) (seniority_3, label("Women + Year + Party FE")) , drop(_cons) xline(0) keep(gender) name(plot_seniority, replace) title("Public seniority") legend(position(6) rows(1)) 
coefplot (national_politics_exp_1, label("Women")) (national_politics_exp_2, label("Women + Year")) (national_politics_exp_3, label("Women + Year + Party FE")) , drop(_cons) xline(0) keep(gender) name(plot_national_politics_exp, replace) title("National seniority") legend(position(6) rows(1)) 
coefplot (childless_1, label("Women")) (childless_2, label("Women + Year")) (childless_3, label("Women + Year + Party FE")) , drop(_cons) xline(0) keep(gender) name(plot_childless, replace) title("Childless") legend(position(6) rows(1)) xlabel(0(.05).2)
	
grc1leg plot_age plot_university_degree plot_isei plot_childless plot_seniority plot_national_politics_exp , rows(2) title("(a) Individual factors") name(individual, replace) fxsize(400) fysize(400)

coefplot (years_as_party_member_1, label("Women")) (years_as_party_member_2, label("Women + Year")) (years_as_party_member_3, label("Women + Year + Party FE")) , drop(_cons) xline(0) keep(gender) name(plot_years_as_party_member, replace) title("Party seniority") legend(position(6) rows(1)) xlabel(-5(1)0)
coefplot (youth_org_1, label("Women")) (youth_org_2, label("Women + Year")) (youth_org_3, label("Women + Year + Party FE")) , drop(_cons) xline(0) keep(gender) name(plot_youth_org, replace) title("Youth organization") legend(position(6) rows(1)) 
coefplot (leader_coincidence_1, label("Women")) (leader_coincidence_2, label("Women + Year")) (leader_coincidence_3, label("Women + Year + Party FE")) , drop(_cons) xline(0) keep(gender) name(plot_leader_coincidence, replace) title("Contact with the leader") legend(position(6) rows(1)) xlabel(0(.2)-1.2)

grc1leg plot_years_as_party_member plot_youth_org plot_leader_coincidence   , rows(2) title("(b) Interpersonal factors") name(interpersonal, replace) fxsize(300) fysize(400) hole(3) 

grc1leg individual interpersonal, rows(1) xsize(6) ysize(8) 
graph export "genderdifferences.pdf" , replace













